package com.muyu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.mapper.LogInfoMapper;
import com.muyu.model.entity.LogInfoEntity;
import com.muyu.model.excel.ExportExcelLogInfo;
import com.muyu.service.LogInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: LogInfoServiceImpl
 * @Author: Zirun.Xin
 * @Date: 2025/4/11 下午3:06
 * @Version: 1.0
 * @Description: 日志信息业务实现层
 */
@Service
@RequiredArgsConstructor
public class LogInfoServiceImpl extends ServiceImpl<LogInfoMapper, LogInfoEntity> implements LogInfoService {

    /**
     * 日志信息持久层
     */
    private final LogInfoMapper logInfoMapper;

    /**
     * 映射ExportExcelLogInfo对象
     *
     * @param list 日志信息实体数据
     * @return 导出日志信息对象集合
     */
    @Override
    public List<ExportExcelLogInfo> mapExportExcelLogInfo(List<LogInfoEntity> list) {
        return list.stream().map(logInfoEntity ->
                ExportExcelLogInfo.builder()
                        .type(logInfoEntity.getType())
                        .operation(logInfoEntity.getOperation())
                        .responseCode(logInfoEntity.getResponseCode())
                        .operateTime(logInfoEntity.getOperateTime())
                        .spendTime(logInfoEntity.getSpendTime())
                        .url(logInfoEntity.getUrl())
                        .body(logInfoEntity.getBody())
                        .ip(logInfoEntity.getIp())
                        .query(logInfoEntity.getQuery())
                        .exception(logInfoEntity.getException())
                        .build()
        ).collect(Collectors.toList());
    }
}
